<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script type="text/javascript">

var func;

$(document).ready(function() {
	$("#board_all_check").on("click", function() {
		$(".board_check").prop('checked', this.checked); 
	});
});

function sendForm(value) {
	func = window.document.func;
	//form 객체 조회
	if(value==1) {
		sortForm();
	} else if(value==2) {
		//팝업창으로 설정
		settingForm(value);
		func.bid.value = 0;
	} else if(value==3) {
		if($(".board_check:checked").length != 0) {
			func.target = '';
			func.action = "/${initParam.context_root }/board/boardDelete.do";	
		} else {
			alert("삭제할 게시판을 선택해주세요.");
			return false;
		}
	} 
	func.submit();	//폼전송 메소드
}


function selectForm(value) {
	func = window.document.func;
	//팝업창으로 설정
	settingForm(value);	
	func.submit();	//폼전송 메소드
}

function selectBoard(value) {
	func = window.document.func; 
	func.action = "/${initParam.context_root }/board/list.do";
	func.target = '';
	func.bid.value = value;
	func.submit();	//폼전송 메소드
}

function settingForm(value) {
	window.open('', 'board_setting', 'width=750, height=675');
	func.action = "/${initParam.context_root }/board/boardSetting.do";
	func.target = 'board_setting';
	func.bid.value = value;
}

function sortForm() {
	window.open('', 'board_setting', 'width=260, height=290');
	func.action = "/${initParam.context_root }/board/boardSort.do";
	func.target = 'board_setting';
}
</script>
<h3>게시판 관리</h3><hr>
<h4>게시판목록</h4>
<form id="func" name="func" method="post">
	<p><input type="button" id="order_btn" value="표시순서 변경" onclick="sendForm(1)"></p>
	<c:if test="${fn:length(requestScope.boardList) != 0 }">
		<table class="table table-bordered" id="board_list" border='1' cellspacing="0">
			<thead>
				<tr style="background-color:#453949; color: white;"align="center">
					<td><input type="checkbox" id="board_all_check"></td>
					<td>분류</td>
					<td>게시판제목</td>
					<td>게시판 ID</td>
					<td>권한(쓰기/읽기)</td>
					<td>새글/총갯수</td>
					<td>게시물 관리</td>
					<td>공개여부</td>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${requestScope.boardList }" var="board">
					<tr align="center">
						<td><input type="checkbox" name="board_check" class="board_check" value="${board.boardId}"></td>
						<td>${board.boardClass}</td>
						<td onclick="selectForm(${board.boardId})"><a>${board.boardTitle}</a></td>
						<td>${board.boardId}</td>
						<td>${board.wPermission} / ${board.rPermission}</td>
						<td> / ${board.allPaper}</td>
						<td onclick="selectBoard(${board.boardId})"><a>게시판 바로가기</a></td>
						<td>${board.open}</td>
					</tr> 
				</c:forEach>
			</tbody>
		</table>
	</c:if>
	
	<input type="hidden" name="bid">
	<p align="center"><input type="button" id="add_btn" value="게시판 등록" onclick="sendForm(2)">&nbsp;&nbsp;&nbsp;<input type="button" id="delete_btn" value="삭제" onclick="return sendForm(3)"></p>
</form>